package org.ht.demo.openapi.util;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.ht.demo.openapi.bean.IotMetadataValue;
import org.ht.demo.openapi.bean.IotXdsmokeLog;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 2018-09
 * @author
 *
 */

public class DeviceUtils {


	/**
	 * NB解析
	 * @param ygdata
	 * @return
	 */
	public static IotXdsmokeLog buileYgFl(String ygdata) {
		ygdata=ygdata.toLowerCase();
		IotXdsmokeLog smokeLog=new IotXdsmokeLog();
		if("55".equalsIgnoreCase(DeviceUtils.buileWei(ygdata,1,0))){
			int datalength=Integer.parseInt(DeviceUtils.buileWei(ygdata,3,4),16);
			int devType=Integer.parseInt(DeviceUtils.buileWei(ygdata,5,0),16);
			String imei0=DeviceUtils.buileWei(ygdata,6,13);
			String imei=imei0.substring(0,imei0.length()-1);
			String imsi=DeviceUtils.buileWei(ygdata,14,21);
			int dsignal=Integer.parseInt(DeviceUtils.buileWei(ygdata,22,0),16);  //信号强度
			Integer voltagevalue= Integer.parseInt(DeviceUtils.buileWei(ygdata,38,0),16)*100;   //mV
			String wendu= DeviceUtils.buileWei(ygdata,40,0);  //温度
			String shidu= DeviceUtils.buileWei(ygdata,41,0);  //湿度
			String stu=DeviceUtils.buileWei(ygdata,42,0);  //状态
			String evt=DeviceUtils.buileWei(ygdata,43,0);  //状态
			//smokeLog.setCommand(ygdata);
			smokeLog.setImei(imei);
			smokeLog.setMac(imei);

			smokeLog.setCcid(imsi.substring(0, imsi.length() - 1));
			if(ygdata.length()>=120){
				smokeLog.setImsi(imsi.substring(0, imsi.length() - 1));
				smokeLog.setCcid(DeviceUtils.buileWei(ygdata,45,54));
				smokeLog.setVersion(DeviceUtils.buileWei(ygdata,56,0));
			}
			if(dsignal!=99){
				smokeLog.setDsignal(dsignal);
				smokeLog.setSignal(dsignal);
			}
			smokeLog.setCcc(stu);
			if(voltagevalue!=25500){
				smokeLog.setVoltagevalue(voltagevalue);
			}

			smokeLog.setMessagetype(0);
			if(!"80".equalsIgnoreCase(wendu)){
				if(Integer.parseInt(wendu,16)<130){
					smokeLog.setTvalue(Integer.parseInt(wendu,16)+"");
				}
			}else{
				smokeLog.setTvalue(null);
			}

			switch(evt){
				case "00" :  //其他
					smokeLog.setMessagetype(0);
					break;
				case "01" :  //心跳
					smokeLog.setMessagetype(1);
					break;
				case "03" :  //报警恢复
					smokeLog.setMessagetype(3);
					break;
				case "04" :  //防拆报警
					smokeLog.setMessagetype(4);

					break;
				case "05" :  //防拆报警恢复
					smokeLog.setMessagetype(5);
					break;
				case "0a" :  //测试，自检
					smokeLog.setMessagetype(8);
					smokeLog.setBjcode("960");
					smokeLog.setStatedesc("报警测试");
					break;
				case "06" :  //低压
					smokeLog.setMessagetype(6);
					smokeLog.setBjcode("384");
					smokeLog.setStatedesc("电池低压报警");
					break;
				case "07" :  //低压恢复
					smokeLog.setMessagetype(7);
					break;
				case "02" :  //报警
					smokeLog.setMessagetype(2);
					break;
				case "10" :  //温度报警
					smokeLog.setMessagetype(13);
					smokeLog.setBjcode("986");
					smokeLog.setStatedesc("高温报警");
					break;
				case "11" :  //温度报警恢复
					smokeLog.setMessagetype(14);
					break;
				case "12" :  //人体红外报警
					smokeLog.setMessagetype(15);
					smokeLog.setBjcode("934");
					smokeLog.setStatedesc("人体红外报警");
					break;
				case "13" :
					if(devType==3){ //气体报警
						smokeLog.setMessagetype(15);
					}
					break;
				case "14" :
					if(devType==5){
						smokeLog.setMessagetype(28);
						smokeLog.setStatedesc("人体红外探测无人");
					}

					break;
				case "15" :  //低温报警
					smokeLog.setMessagetype(21);
					smokeLog.setBjcode("TY001");
					smokeLog.setStatedesc("低温报警");
					break;
				case "16" :  //湿度低报警
					smokeLog.setMessagetype(22);
					break;
				case "17" :  //湿度高报警
					smokeLog.setMessagetype(23);
					break;
				case "0e" :  //探测器故障
					smokeLog.setMessagetype(9);
					break;
				case "0f" :  //探测器故障恢复
					smokeLog.setMessagetype(10);
					break;
				case "21" :  //回复设定报警温湿度下限
					smokeLog.setMessagetype(25);
					BigInteger fbi = new BigInteger(wendu, 16);
					BigInteger bigint=new BigInteger(wendu, 16);

					break;
				case "22" :  //回复设定报警温湿度上限
					smokeLog.setMessagetype(25);
					break;
				case "23" :  //复合型产品，燃气报警
					if(devType==4){
						smokeLog.setMessagetype(26);
						smokeLog.setStatedesc("燃气报警");
						smokeLog.setBjcode("TY001");
					}

					break;
				case "24" :  //复合型产品，CO报警
					smokeLog.setMessagetype(27);
					smokeLog.setStatedesc("CO报警");
					smokeLog.setBjcode("TY001");
					break;
				default : //可选

					//语句
			}

			//状态
			String st2=StringUtil.hexString2binaryString(stu);
			int bjs=Integer.parseInt(st2.charAt(st2.length()-1)+"");  //报警
			int fcs=Integer.parseInt(st2.charAt(st2.length()-3)+"");  //防拆状态
			int dcs=Integer.parseInt(st2.charAt(st2.length()-4)+"");  //电池状态
			int wds=Integer.parseInt(st2.charAt(st2.length()-7)+"");  //报警
			smokeLog.setTamperstatus(fcs);
			smokeLog.setBatterys(dcs==0?1:0);
			switch(devType){
				case 1 :
					smokeLog.setDevicetype("MC");
					smokeLog.setDoorstatus(0);
					if(smokeLog.getMessagetype()==2){
						smokeLog.setBjcode("989");  //门磁报警
						smokeLog.setDoorstatus(1);
						smokeLog.setStatedesc("门磁报警");
					}
					break;
				case 2 :
					smokeLog.setDevicetype("LS");
					if(smokeLog.getMessagetype()==2){
						smokeLog.setBjcode("969");
						smokeLog.setStatedesc("漏水报警");
					}
					break;
				case 3 :
					smokeLog.setDevicetype("YG");
					if(smokeLog.getMessagetype()==2){
						smokeLog.setBjcode("111");
						smokeLog.setStatedesc("烟雾报警");
					}
					break;
				case 4 :
					smokeLog.setDevicetype("QG");
					if(smokeLog.getMessagetype()==2){
						smokeLog.setBjcode("991");
						smokeLog.setStatedesc("燃气报警");
						if("866283064567311".equals(smokeLog.getMac())){
							smokeLog.setBjcode("990");
						}
					}
					if(smokeLog.getMessagetype()==4){
						smokeLog.setMessagetype(0);
					}

					break;
				case 5 :
					if(smokeLog.getMessagetype()==2){
						smokeLog.setBjcode("934");
						smokeLog.setStatedesc("红外报警");
					}
					smokeLog.setDevicetype("HW");
					break;
				case 6 :
					if(smokeLog.getMessagetype()==2){
						smokeLog.setBjcode("TY001");
						smokeLog.setStatedesc("一氧化碳报警");
					}
					smokeLog.setDevicetype("CO");
					break;
				case 7 :
					if(smokeLog.getMessagetype()==2){
						smokeLog.setBjcode("990");
						smokeLog.setStatedesc("紧急按钮报警");
					}
					smokeLog.setDevicetype("XS");
					break;
				case 8 :
					smokeLog.setDevicetype("WSD");  //温湿度
					smokeLog.setTamperstatus(null);

					if(smokeLog.getMessagetype()==2){
						smokeLog.setBjcode("986");
						smokeLog.setStatedesc("高温报警");
					}
					break;
				default : //可选
					//语句
			}
		}
		return smokeLog;
	}


	public static IotXdsmokeLog TYbuile4GFl(String ygdata,String devicetype){
		ygdata=ygdata.toLowerCase();
		String mydevicetype=devicetype;
		IotXdsmokeLog smokeLog=new IotXdsmokeLog();
		smokeLog.setMessagetype(0);
		if("57544b".equalsIgnoreCase(DeviceUtils.buileWei(ygdata,1,3))){
			smokeLog.setMessagetype(31);
			smokeLog.setVersion(DeviceUtils.buileWei(ygdata,4,0));
			String csb=DeviceUtils.buileWei(ygdata,5,6);
			String datano=DeviceUtils.buileWei(ygdata,7,8);
			String cmd=DeviceUtils.buileWei(ygdata,9,0);
			Integer clength=0;
			String content="";
			if("464c".equalsIgnoreCase(csb)||"0F31".equalsIgnoreCase(csb)){
				clength=Integer.parseInt(buileWei(ygdata, 10, 11),16);  //内容长度
				content=buileWei(ygdata, 12, 11+clength);
				if("464c".equalsIgnoreCase(csb)){
					devicetype="YG-XY";
				}

			}else{
				clength=Integer.parseInt(buileWei(ygdata, 10, 0),16);  //内容长度
				content=buileWei(ygdata, 11, 10+clength);
			}

			String imei="";
			if("05".equals(cmd)){
				imei = StringUtil.hexStringToString(buileWei(content, 1, 15));
			}else {
				imei = StringUtil.hexStringToString(buileWei(content, 2, 16));
			}
			smokeLog.setMac(imei);
			smokeLog.setImei(imei);
			if("01".equals(cmd)){
				String dt=buileWei(content, 1,0);
				if(Validator.isNull(devicetype)){
					if("01".equals(dt)){
						smokeLog.setDevicetype("MC");
					}else if("02".equals(dt)){
						smokeLog.setDevicetype("QG");
					}else if("03".equals(dt)){
						smokeLog.setDevicetype("YG");
					}else if("04".equals(dt)){
						smokeLog.setDevicetype("XS");
					}else if("05".equals(dt)){
						smokeLog.setDevicetype("CO");
						smokeLog.setType(23);
					}else if("08".equals(dt)){
						smokeLog.setDevicetype("LS");
					}else if("25".equals(dt)){
						smokeLog.setDevicetype("QG");
					}else if("09".equals(dt)){
						smokeLog.setDevicetype("PM");   //
					}else if("55".equals(dt)){   //通用板子
						smokeLog.setDevicetype("TYZ");   //
					}
					devicetype=smokeLog.getDevicetype();
				}

				smokeLog.setMessagetype(0);
				smokeLog.setImsi(StringUtil.hexStringToString(buileWei(content, 17,31)));
				smokeLog.setCcid(StringUtil.hexStringToString(buileWei(content, 32,51)));
				Integer vl=Integer.parseInt(DeviceUtils.buileWei(content,52,0),16);
				smokeLog.setVoltagevalue(vl*100);   //mV
				if(vl==255||vl==0){
					smokeLog.setVoltagevalue(null);
					smokeLog.setVolvalue(null);
				}


				int dsignal=Integer.parseInt(DeviceUtils.buileWei(content,53,0),16);  //信号强度
				smokeLog.setDsignal(dsignal);
				smokeLog.setSignal(dsignal);

			}else if("02".equals(cmd)){
				if(Validator.isNull(devicetype)){
					String dt=buileWei(content, 1,0);
					if("01".equals(dt)){
						smokeLog.setDevicetype("MC");
					}else if("02".equals(dt)){
						smokeLog.setDevicetype("QG");
					}else if("03".equals(dt)){
						smokeLog.setDevicetype("YG");
					}else if("04".equals(dt)){
						smokeLog.setDevicetype("XS");
					}else if("05".equals(dt)){
						smokeLog.setDevicetype("CO");
						smokeLog.setType(23);
					}else if("08".equals(dt)){
						smokeLog.setDevicetype("LS");
					}else if("25".equals(dt)){
						smokeLog.setDevicetype("QG");
					}else if("09".equals(dt)){
						smokeLog.setDevicetype("PM");   //
					}else if("55".equals(dt)){   //通用板子
						smokeLog.setDevicetype("TYZ");   //
					}
					devicetype=smokeLog.getDevicetype();
				}

				String etype=buileWei(content, 17,0);
				if("01".equals(etype)){   //心跳
					smokeLog.setMessagetype(1);
				}else if("02".equals(etype)){  //  报警
					smokeLog.setMessagetype(2);
					if("QG".equals(smokeLog.getDevicetype())){
						smokeLog.setBjcode("991");
						smokeLog.setStatedesc("燃气报警");
					}
					if("CO".equals(smokeLog.getDevicetype())){
						smokeLog.setBjcode("TY001");
						smokeLog.setStatedesc("一氧化碳报警");
					}
					if("YG".equals(smokeLog.getDevicetype())){
						smokeLog.setBjcode("111");
						smokeLog.setStatedesc("烟雾报警");
					}
					if("LS".equals(smokeLog.getDevicetype())){
						smokeLog.setBjcode("969");
						smokeLog.setStatedesc("漏水报警");
					}
					if("MC".equals(smokeLog.getDevicetype())){
						smokeLog.setBjcode("989");  //门磁报警
						smokeLog.setDoorstatus(1);
						smokeLog.setStatedesc("门磁报警");

						if("860339061657673".equalsIgnoreCase(smokeLog.getMac())){
							smokeLog.setBjcode("FHM-TIME");  //门磁报警
							smokeLog.setStatedesc("未关门检测");
							smokeLog.setDoorstatus(1);
						}
					}
					if("XS".equals(smokeLog.getDevicetype())){
						smokeLog.setBjcode("990");  //紧急按钮报警
						smokeLog.setStatedesc("紧急按钮报警");
					}
				}else if("03".equals(etype)){  //  恢复报警
					smokeLog.setMessagetype(3);
				}else if("04".equals(etype)){  //  防拆报警
					smokeLog.setMessagetype(4);
					smokeLog.setTamperstatus(1);
				}else if("05".equals(etype)){  //  防拆报警恢复
					smokeLog.setMessagetype(5);
					smokeLog.setTamperstatus(0);
				}else if("06".equals(etype)){  //  低压
					smokeLog.setMessagetype(6);
					smokeLog.setBjcode("384");
					smokeLog.setStatedesc("电池低压告警");
				}else if("07".equals(etype)){  //  低压恢复   smokeLog.setBjcode("990");
					smokeLog.setMessagetype(7);
				}else if("08".equals(etype)){  // sos 报警   //故障
					if("XS".equals(smokeLog.getDevicetype())){
						smokeLog.setBjcode("990"); //
						smokeLog.setStatedesc("紧急按钮报警");
						smokeLog.setMessagetype(2);
					}else{
						smokeLog.setMessagetype(28);
						smokeLog.setBjcode("TY001"); //
						smokeLog.setStatedesc("传感器故障");
					}

				}else if("09".equals(etype)){  // sos 报警恢复   //传感器故障恢复
					if("XS".equals(smokeLog.getDevicetype())){
						smokeLog.setMessagetype(3);
					}else{
						smokeLog.setMessagetype(28);
						smokeLog.setStatedesc("传感器故障恢复");
					}

				}else if("0a".equalsIgnoreCase(etype)){  // HELP 请求
					//smokeLog.setMessagetype(17);
					smokeLog.setMessagetype(8);
					smokeLog.setBjcode("960");
					smokeLog.setStatedesc("报警测试");
				}else if("0b".equalsIgnoreCase(etype)){  // HELP 恢复
					smokeLog.setMessagetype(18);
				}else if("12".equals(etype)){  // CO
					if("CO".equalsIgnoreCase(devicetype)||"QG".equalsIgnoreCase(devicetype)){
						smokeLog.setMessagetype(27);
						smokeLog.setStatedesc("CO报警");
						smokeLog.setBjcode("TY001");
					}

				}else if("0e".equalsIgnoreCase(etype)){
					if("YG".equalsIgnoreCase(devicetype)||"WSD".equalsIgnoreCase(devicetype)){
						smokeLog.setMessagetype(13);
						smokeLog.setBjcode("986");
						smokeLog.setStatedesc("高温报警");
					}

				}else if("0f".equalsIgnoreCase(etype)){
					smokeLog.setMessagetype(13);
				}else if("0D".equalsIgnoreCase(etype)){
					if("XS".equals(smokeLog.getDevicetype())){
						smokeLog.setMessagetype(3);
					}
				}


				if(Validator.isNotNull(devicetype)){
					if("MC".equalsIgnoreCase(devicetype)){
						smokeLog.setVoltagevalue(Integer.parseInt(DeviceUtils.buileWei(content,18,0),16)*100);   //mV
						int dsignal=Integer.parseInt(DeviceUtils.buileWei(content,19,0),16);  //信号强度
						smokeLog.setDsignal(dsignal);
						smokeLog.setSignal(dsignal);
						smokeLog.setVolvalue(Integer.parseInt(DeviceUtils.buileWei(content,20,0),16));   //mV
					}
					if("XS".equalsIgnoreCase(devicetype)){
						smokeLog.setVoltagevalue(Integer.parseInt(DeviceUtils.buileWei(content,18,0),16)*100);   //mV
						int dsignal=Integer.parseInt(DeviceUtils.buileWei(content,19,0),16);  //信号强度
						smokeLog.setDsignal(dsignal);
						smokeLog.setSignal(dsignal);
					}
					if("YG".equalsIgnoreCase(devicetype)||"LS".equalsIgnoreCase(devicetype)||devicetype.contains("YG-")){
						smokeLog.setVoltagevalue(Integer.parseInt(DeviceUtils.buileWei(content,18,0),16)*100);   //mV
						int dsignal=Integer.parseInt(DeviceUtils.buileWei(content,19,0),16);  //信号强度
						smokeLog.setDsignal(dsignal);
						smokeLog.setSignal(dsignal);
						smokeLog.setVolvalue(Integer.parseInt(DeviceUtils.buileWei(content,20,0),16));   //mV
						int wd=Integer.parseInt(DeviceUtils.buileWei(ygdata,6,0),16);  //温度
						if(wd<100){
							smokeLog.setTvalue(wd+"");
						}
						if("09".equals(smokeLog.getVersion())){
							smokeLog.setData(Integer.parseInt(DeviceUtils.buileWei(ygdata,5,0),16)+"");
							smokeLog.setDataunit("浓度");
							smokeLog.setTvalue(Integer.parseInt(DeviceUtils.buileWei(ygdata,6,0),16)+"");
						}

					}
					if("QG".equalsIgnoreCase(devicetype)){
						smokeLog.setData(Integer.parseInt(DeviceUtils.buileWei(content,18,0),16)+"");   //燃气浓度值
						smokeLog.setDataunit("%LEL");
						int dsignal=Integer.parseInt(DeviceUtils.buileWei(content,20,0),16);  //信号强度
						smokeLog.setDsignal(dsignal);
						smokeLog.setSignal(dsignal);
					}
					if("YG-XY".equalsIgnoreCase(devicetype)){
						int dsignal=Integer.parseInt(DeviceUtils.buileWei(content,20,0),16);  //信号强度
						smokeLog.setDsignal(dsignal);
						smokeLog.setSignal(dsignal);
					}
					if("YG-XY-02".equalsIgnoreCase(devicetype)){
						int dsignal=Integer.parseInt(DeviceUtils.buileWei(content,20,0),16);  //信号强度
						smokeLog.setDsignal(dsignal);
						smokeLog.setSignal(dsignal);
					}
					if("CO".equalsIgnoreCase(devicetype)){
						smokeLog.setData(Integer.parseInt(DeviceUtils.buileWei(content,18,19),16)+"");   //一氧化碳浓度值
						smokeLog.setDataunit("PPM");
						smokeLog.setVoltagevalue(Integer.parseInt(DeviceUtils.buileWei(content,20,0),16)*100);   //mV
						int dsignal=Integer.parseInt(DeviceUtils.buileWei(content,21,0),16);  //信号强度
						smokeLog.setDsignal(dsignal);
						smokeLog.setSignal(dsignal);
						smokeLog.setVolvalue(Integer.parseInt(DeviceUtils.buileWei(content,22,0),16));   //mV
					}

					if(Validator.isNotNull(mydevicetype)){
						if(mydevicetype.contains("TYZ-")) {  //通用板子-烟感
							smokeLog.setBjcode(null);
							smokeLog.setStatedesc(null);
							smokeLog.setMessagetype(1);
							int dsignal=Integer.parseInt(DeviceUtils.buileWei(content,17,0),16);  //信号强度
							smokeLog.setDsignal(dsignal);
							smokeLog.setSignal(dsignal);
							smokeLog.setDevicetype(StringUtil.obgStrToArray(mydevicetype,"-")[1]);
							if("01".equals(DeviceUtils.buileWei(content,18,0))){
								smokeLog.setMessagetype(2);
								smokeLog.setBjcode("TY001");
								smokeLog.setStatedesc("报警");
								if("YG".equals(smokeLog.getDevicetype())){
									smokeLog.setStatedesc("烟雾报警");
								}
								if("QG".equals(smokeLog.getDevicetype())){
									smokeLog.setStatedesc("燃气报警");
								}
								if("CO".equals(smokeLog.getDevicetype())){
									smokeLog.setStatedesc("一氧化碳报警");
								}
								if("XS".equals(smokeLog.getDevicetype())){
									smokeLog.setStatedesc("SOS报警");
								}

							}

						}
					}

					if("TYZ".equalsIgnoreCase(devicetype)){  //通用板子
						int dsignal=Integer.parseInt(DeviceUtils.buileWei(content,17,0),16);  //信号强度
						smokeLog.setDsignal(dsignal);
						smokeLog.setSignal(dsignal);
						Integer tl=Integer.parseInt(DeviceUtils.buileWei(content,20,0),16);
						String tdata=DeviceUtils.buileWei(ygdata,10+21,10+21+tl);
						smokeLog.setMessagetype(31);
						if("5a".equals(DeviceUtils.buileWei(tdata,1,0))){
							Integer tl_le=Integer.parseInt(DeviceUtils.buileWei(tdata,2,0),16);
							String tdata_tc=DeviceUtils.buileWei(tdata,3,3+tl_le);
							String dtycode=DeviceUtils.buileWei(tdata_tc,1,0);
							String bjname="";
							smokeLog.setMessagetype(28);

							if(Validator.isNull(devicetype)){
								if ("01".equals(dtycode)) {
									smokeLog.setDevicetype("QG");
									bjname = "燃气";
								} else if ("02".equals(dtycode)) {
									smokeLog.setDevicetype("CO");
									bjname = "一氧化碳";
								} else if ("03".equals(dtycode)) {
									smokeLog.setDevicetype("QG");
									bjname = "氧气";
								} else if ("04".equals(dtycode)) {
									smokeLog.setDevicetype("QG");
									bjname = "硫化氢";
								}
							}
							String regsta=StringUtil.hexString2binaryString(DeviceUtils.buileWei(tdata_tc,2,5));
							String chdatasta=StringUtil.hexString2binaryString(DeviceUtils.buileWei(tdata_tc,6,9));
							String tdesc="";

							List<IotMetadataValue> metadataList=new ArrayList<>();

							for (int i = 1; i <= regsta.length(); i++) {
								if("1".equals(regsta.charAt(regsta.length()-i)+"")){
									IotMetadataValue cov=new IotMetadataValue();
									cov.setProperty(smokeLog.getDevicetype()+i);
									cov.setPropertyName("通道:"+i);
									cov.setType("string");
									cov.setValue((("1".equals(chdatasta.charAt(chdatasta.length()-i)+""))?"报警":"正常"));
									cov.setFormatValue(cov.getValue());
									metadataList.add(cov);
								}
							}
							smokeLog.setMetadataListJson(JSONObject.toJSONString(metadataList));
						}
					}

				}
			}else if("05".equals(cmd)){
				smokeLog.setMessagetype(31);
				String mac=StringUtil.hexStringToString(buileWei(content, 1,15));
				smokeLog.setMac(mac);
				smokeLog.setImei(mac);
			}else if("04".equals(cmd)){
				smokeLog.setMessagetype(28);
				String mac=StringUtil.hexStringToString(buileWei(content, 1,15));
				smokeLog.setMac(mac);
				smokeLog.setImei(mac);
				smokeLog.setStatedesc("下发指令回复");
			}

		}
		if(Validator.isNotNull(smokeLog.getVoltagevalue()+"")){
			if(smokeLog.getVoltagevalue()==0){
				smokeLog.setVoltagevalue(null);
			}
		}
		if(Validator.isNotNull(smokeLog.getVolvalue()+"")){
			if(smokeLog.getVolvalue()==0){
				smokeLog.setVolvalue(null);
			}
		}

		if(Validator.isNotNull(smokeLog.getDevicetype())){
			if("QG".equals(smokeLog.getDevicetype())){
				smokeLog.setTamperstatus(null);
				smokeLog.setDoorstatus(null);
				smokeLog.setTvalue(null);
				smokeLog.setVoltagevalue(null);
				smokeLog.setVolvalue(null);
				smokeLog.setBatterys(null);
			}

			if("XS".equals(smokeLog.getDevicetype())){
				smokeLog.setTamperstatus(null);
				smokeLog.setDoorstatus(null);
				smokeLog.setTvalue(null);
			}
			if("YG-XY".equals(smokeLog.getDevicetype())){  //吸烟报警器
				smokeLog.setDevicetype("YG");
				if(smokeLog.getMessagetype()==2){
					smokeLog.setBjcode("TY001");
					smokeLog.setStatedesc("吸烟报警");
				}
			}
		}

		return smokeLog;
	}


	public static String buileWei(String data,Integer starl,Integer endl) {
		String rs="";
		if (endl==0) {
			rs=data.substring(starl*2-2, starl*2);
			return rs;
		}
		rs=data.substring(starl*2-2, endl*2);
		return rs;
		
	}


	
	public static String Gparse(String str) {
		try {
			if("ffffffbf".equals(str)) {
				return "0";
			}
			if("8".equals(str.substring(0, 1))) {
				return "-"+(float)Long.parseLong(str.substring(1, 7),16)/1000+"";
			}else {
				return ""+(float)Long.parseLong(str,16)/1000+"";
			}
		} catch (Exception e) {
			return "0";
		}
		
	}
	// 	电压  判断  strA ==1  过压  strB ==1 欠压
	public static String isvoltagea(String strA,String strB) {
		try {
			if("1".equals(strA)) {
				return "1";
			}
			if("1".equals(strB)) {
				return "2";
			}
			return "0";
		} catch (Exception e) {
			return "0";
		}

	}

	// 	ZC数据格式化
	public static String ZCdatafilter1(String data,int radix,float division) {
		return String.format("%.1f", Integer.parseInt(data,radix)/division);
	}

	// 	ZC数据格式化
	public static String ZCdatafilter(String data,int radix,float division) {
		return String.format("%.2f", Integer.parseInt(data,radix)/division);
	}
	// 	ZC功率格式化 KW
	public static String ZCgonglvgeshua(String data,int starl,int endl) {
		if ("00000000".equals(buileWei(data, starl, endl))){
			return "0";
		}
		if ("00000001".equals(buileWei(data, starl, endl))){
			return "1";
		}
		String bufer=Integer.toBinaryString((int) Long.parseLong(buileWei(data, starl, endl),16));
		double value=Integer.parseInt(bufer.substring(1,bufer.length()), 2)/(double)1000;
		if ("1".equals(bufer.substring(0, 1))) {
			value=value*-1;
		}
		return String.valueOf(value);
	}



}
